package com.css.dzj.dzjzhfx.common.menu;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.css.aq.server.service.BaseService;
import com.css.dzj.dzjzhfx.common.util.R;
import com.css.dzj.dzjzhfx.common.util.Restful.RestfulUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.http.HttpMethod;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/dict")
@PropertySource(value = "classpath:base.properties")
public class GetDictController {
    @Autowired
    private HttpServletRequest request;
    @Value("${BASE_URL}")
    private String BASE_URL;
    /**
     * 获取字典项
     *
     * @param category
     * @return
     */
    @PostMapping("/getdict/{category}")
    public R getDict(@PathVariable String category) {
        String url = BASE_URL + "/platform/api/sys/dicts/dictitems/dictcode/" + category;
        Map<String, String> map = new HashMap<>();
        HttpMethod method = HttpMethod.GET;
        List result = (List) RestfulUtil.sendRestful(request, map, url, method).get("data");
        String data = JSON.toJSONString(result);
        JSONArray jsonArray = JSONArray.parseArray(data);
        System.out.println(jsonArray);
        return R.ok().put("data", jsonArray);
    }
}
